package com.mapbased.wfw;

import java.net.*;

import com.google.gwt.user.server.rpc.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class GWTHandler
    extends PageHandler implements SerializationPolicyProvider
{
    private SerializationPolicy cachedSerializationPolicy;

    /**
     * Returns a {@link SerializationPolicy} for a given module base URL and
     * serialization policy strong name.
     *
     * @param moduleBaseURL the URL for the module
     * @param serializationPolicyStrongName strong name of the serialization
     *   policy for the specified module URL
     * @return a {@link SerializationPolicy} for a given module base URL and
     *   RPC strong name; must not return <code>null</code>
     * @todo Implement this
     *   com.google.gwt.user.server.rpc.SerializationPolicyProvider method
     */

    public synchronized SerializationPolicy getSerializationPolicy(String
        moduleBaseURL,
        String serializationPolicyStrongName)
    {
        if(this.cachedSerializationPolicy == null)
        {
            String serializationPolicyFilePath=
                SerializationPolicyLoader.getSerializationPolicyFileName(
                    moduleBaseURL + serializationPolicyStrongName);

            try
            {
                java.net.URL u=new URL(serializationPolicyFilePath);

                this.cachedSerializationPolicy=SerializationPolicyLoader.
                    loadFromStream(u.openStream());
            }
            catch(Exception ex)
            {
                throw new java.lang.RuntimeException("Error while loading:" +
                    serializationPolicyFilePath,ex);
            }

        }
        return cachedSerializationPolicy;

    }

}
